import { InjectionKey } from 'vue'
import { createStore, Store } from 'vuex'
import getters from '@/store/getters'
export interface State {
    count: number
}

export const key: InjectionKey<Store<State>> = Symbol()

const modulesFiles = import.meta.globEager('./modules/*.ts')

const pathList: string[] = []

for (const path in modulesFiles) {
    pathList.push(path)
}

const modules = pathList.reduce((modules: { [x: string]: any }, modulePath: string) => {
    const moduleName = modulePath.replace(/^\.\/modules\/(.*)\.\w+$/, '$1')
    const value = modulesFiles[modulePath]
    modules[moduleName] = value.default
    return modules
}, {})

const store = createStore({
    modules,
    getters
})
export default store
